
checkLogin();


    var id = GetQueryString('id');
    var success = function (res) {
        var msg = '';
        var status = 0;
        var info = res.data.info;
        var index;
        if(info!=undefined && info != null && info!=''){
            var choose = info.waterbill_category;
            if( choose !=undefined && choose != null && choose != '' && choose.length > 0){
                //将字数超限的项置于上部
                var list_new = choose;
                choose = changeChoose(list_new);

                var text = "额外赠送：";
                choose[0].choosed = true;
                if(choose[0].description != undefined && choose[0].description != null && choose[0].description!=''){
                   choose[0].description =text+ choose[0].description;
                }
                info.waterbill_category = choose;
                var html = template('notice_data', info);     //order 模板id
                $('#myform').append(html);

                //设置套餐处的高度
                setWaterH();
                if(choose[0].title != undefined && choose[0].title != null && choose[0].title!=''){
                    $('.gift-button'+choose[0].id).css('color','red'); //给元素默认样式
                    index = choose[0].id;
                }
                $('.gift-button').bind('click',function () {
                    /*var sPrents = $(this).parents(".choose_id");
                    var goods_id = sPrents.attr('id');*/
                    var goods_id = parseInt(this.getAttribute('data-id'));
                    if(isEmpty(goods_id)){
                        return;
                    }
                    for(var i=0;i<choose.length;i++){
                        $('.gift-button'+choose[i].id).css('color','#333');
                        if(choose[i].id == goods_id){
                            index = choose[i].id;
                            $('.gift-button'+choose[i].id).css('color','red');
                            $('.goods_price').text(choose[i].buy_num * info.goods_price);
                            $('.total_num').text(choose[i].total_num);
                            $('.gift_price').text(choose[i].gift_num * info.goods_price);
                            var des = choose[i].description;
                            if(choose[i].description != undefined && choose[i].description != null && choose[i].description!=''){
                                if(choose[i].description.indexOf('额外赠送') ==-1){
                                    des = text + des;
                                }

                            }
                            $('.description').text(des);
                        }
                    }
                })

                /*//点击购买水票跳转页面
                mui('.toDetail').on('tap','a',function () {
                    var id = info.id;
                    redirect("water-ticket-detail.html?id=" + id + '&index='+index);
                })*/
                $('#button').bind('click',function () {
                    var id = info.id;
                    redirect("water-ticket-detail.html?id=" + id + '&index='+index);
                })
            }
        }
    };
    getData(waterbill_info,combineParams({id:id}),success);

    function changeChoose(list_new) {
        var choose = new Array();
        //将套餐列表中字数超限的项置于上部分
        for(var i=0;i<list_new.length;i++){
            var title_len = list_new[i].title.length;
            if(title_len > 10){
                list_new[i].is_long = 1;
                choose.push(list_new[i]);
            }
        }
        for(var i=0;i<list_new.length;i++){
            var title_len = list_new[i].title.length;
            if(title_len <= 10){
                list_new[i].is_long = 0;
                choose.push(list_new[i]);
            }
        }
        return choose;
    }

  function setWaterH(){
        var allH = $(window).height();
        var top1H = $('.bill-container').outerHeight(true);
        var pH = $('.pH').outerHeight(true);
        var headH = $('.mui-bar').height();
        var footH = $('#button').outerHeight(true);
        var h = allH - top1H - headH - footH - pH;
        console.log(h)
        $('.chose-gift').css('height',h +'px');
  }

